package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import com.ymttest.business.service.shenqi.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.enums.BizOperateLogEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.ChangeOrderDiscountReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.PlaceOrderReq;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderItemVo;
import com.shop2cn.iapi.sqoptrade.resp.Order;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.ChangeOrderDiscountCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.database.sharding.db.sharding.model.OrderBizLogPo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailSubPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.ShenqiProxyChainPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 修改订单折扣和运费(加价或减价) FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SqChangeOrderDiscount {

	private static ChangeOrderDiscountReq changeOrderDiscountReq;
	private static ChangeOrderDiscountCall changeorderdiscountcall;
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();;
	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改订单折扣和运费");
	}

	@Before
	public void caseUp() {

		changeOrderDiscountReq = new ChangeOrderDiscountReq();
		changeorderdiscountcall = new ChangeOrderDiscountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(changeorderdiscountcall.getOpurl());
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void verifyOrderDetailDb(Order order, boolean hasSubPro) {
		this.verifyOrderDetailDb(order, hasSubPro, null);
	}
	
	/**
	 * 校验订单商品表(order_detail)
	 * @param orderId
	 * @param hasSubPro 是否含有组合商品
	 */
	private void verifyOrderDetailDb(Order order, boolean hasSubPro, String address) {

		long orderId = order.getOrderId();

		BigDecimal oldFreight = order.getOrderPo().getFreight();

		OrderPo actualOrderPo = orderShardingWapper
				.selectOrderbyOrderId(orderId);

		Logger.comment(String.format("校验订单商品表(order) orderId:%s",
				actualOrderPo.getOrderId()));

		DataUtil.verifyDecimalEquals(changeOrderDiscountReq.getFreight(),
				actualOrderPo.getFreight(), "验证数据库Freight");

		DataUtil.verifyDecimalEquals(changeOrderDiscountReq.getDiscount(),
				actualOrderPo.getOrderDiscount(), "验证数据库orderDiscount");
		
		BigDecimal orderPayableAmount = actualOrderPo
				.getTotalPrice()
				.add(Utils.zeroIfNull(actualOrderPo.getFreight()))
				.add(Utils.zeroIfNull(actualOrderPo.getOrderDiscount()))
				.add(Utils.zeroIfNull(actualOrderPo.getTaxFee()))
				.add(Utils.zeroIfNull(actualOrderPo.getServiceAmount()))
				.subtract(Utils.zeroIfNull(actualOrderPo.getYmtCouponAmount()))
				.subtract(
						Utils.zeroIfNull(actualOrderPo.getSellerCouponAmount()))
				.subtract(Utils.zeroIfNull(actualOrderPo.getPromotionAmount()))
				.subtract(
						Utils.zeroIfNull(actualOrderPo.getYmtPromotionAmount()))
				.subtract(
						Utils.zeroIfNull(actualOrderPo
								.getIntegralDeductionAmount()));

		DataUtil.verifyDecimalEquals(orderPayableAmount,
				actualOrderPo.getPayableAmount(), "验证数据库payableAmount");

		List<OrderDetailPo> actualOrderDetails = orderShardingWapper
				.selectOrderDetailbyOrderId(orderId);

		BigDecimal[] weightPro = new BigDecimal[actualOrderDetails.size()];

		BigDecimal[] weight = new BigDecimal[actualOrderDetails.size()];

		// 码头订单按商品成交价分摊运费
		for (int j = 0; j < actualOrderDetails.size(); j++) {

			OrderDetailPo orderDetailPo = actualOrderDetails.get(j);
			
			weightPro[j] = orderDetailPo.getProductPrice().multiply(
					new BigDecimal(orderDetailPo.getProductCount()));

			weight[j] = weightPro[j];
		}

		//原路的运费大于0，按订单商品上的运费比例分摊 新运费
		if (Utils.isBiggerThan(oldFreight, BigDecimal.ZERO)) {

			for (int j = 0; j < order.getOrderDetailPoList().size(); j++) {

				OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(
						j);

				weight[j] = orderDetailPo.getFreight();
			}
		}
		
		String currency = actualOrderPo.getCurrency();

		BigDecimal discount = changeOrderDiscountReq.getDiscount();
		BigDecimal freight = changeOrderDiscountReq.getFreight();

		BigDecimal proDiscount[] = Utils.apportionByWeights3(discount,
				weightPro, currency);

		BigDecimal proFreight[] = Utils.apportionByWeights3(freight, weight, currency);

		for (int i = 0; i < actualOrderDetails.size(); i++) {

			OrderDetailPo actualOrderDetail = actualOrderDetails.get(i);

			Logger.comment(String.format(
					"校验订单商品表(order_detail) orderId:%s,OrderDetailId:%s",
					actualOrderDetail.getOrderId(),
					actualOrderDetail.getOrderDetailId()));

			DataUtil.verifyDecimalEquals(proFreight[i],
					actualOrderDetail.getFreight(), "验证数据库Freight");

			Logger.verifyEquals(
					true,
					Utils.calcTimeSpanMin(actualOrderDetail.getUpdateTime()) < 2,
					"验证数据库UpdateTime跟系统当前时间差为2分钟内");

			DataUtil.verifyDecimalEquals(proDiscount[i],
					actualOrderDetail.getDiscount(), "验证数据库Discount");
			
			int scale = 2;
			
			if (null == actualOrderPo.getCurrency()) 
				scale = 2;
			else if (null != actualOrderPo.getCurrency() && actualOrderPo.getCurrency().equalsIgnoreCase("JPY"))
				scale = 0;
			
			boolean fullReductionFreeFreight = Utils.falseIfNull(actualOrderDetail.getFullReductionFreeFreight());
			BigDecimal taxFee = null;
			
			if (SqTradingCallService.isFreePerimeters(Utils.emptyIfNull(address)))
				taxFee = BigDecimal.ZERO;
			else
				taxFee = Utils
						.zeroIfNull(
								fullReductionFreeFreight ? BigDecimal.ZERO
										: actualOrderDetail.getFreight())
						.divide(new BigDecimal(
								actualOrderDetail.getProductCount()), 32,
								RoundingMode.DOWN)
						.add(actualOrderDetail.getProductPrice())
						.add(Utils.zeroIfNull(actualOrderDetail.getDiscount())
								.divide(new BigDecimal(actualOrderDetail
										.getProductCount()), 32,
										RoundingMode.DOWN))
						.subtract(
								Utils.zeroIfNull(actualOrderDetail
										.getYmtCouponAmount()))
						.subtract(
								Utils.zeroIfNull(actualOrderDetail
										.getYmtPromotionAmount()))
						.subtract(
								Utils.zeroIfNull(actualOrderDetail
										.getSellerCouponAmount()))
						.subtract(
								Utils.zeroIfNull(actualOrderDetail
										.getPromotionAmount()))
						.subtract(
								Utils.zeroIfNull(actualOrderDetail
										.getRegionDiscountAmount()))
						.multiply(actualOrderDetail.getTaxRate())
						.setScale(scale, RoundingMode.HALF_DOWN);
			
			DataUtil.verifyDecimalEquals(taxFee, actualOrderDetail.getTaxFee(), "验证数据库TaxFee");

			//订单商品是 套装商品
			if (hasSubPro) {

				//校验订单商品扩展表(order_detail_ext)
				verifyOrderDetailSubDb(actualOrderDetail, currency);
			}
			
			BigDecimal payableAmount = Utils
					.zeroIfNull(
							fullReductionFreeFreight ? BigDecimal.ZERO
									: actualOrderDetail.getFreight())
					.add(actualOrderDetail.getProductPrice()
							.multiply(
									new BigDecimal(actualOrderDetail
											.getProductCount())))
					.add(Utils.zeroIfNull(actualOrderDetail.getDiscount()))
					.add(actualOrderDetail.getTaxFee()
							.multiply(
									new BigDecimal(actualOrderDetail
											.getProductCount())))
					.add(actualOrderDetail.getServiceAmount())
					.subtract(actualOrderDetail.getIntegralDeductionAmount())
					.subtract(
							Utils.zeroIfNull(actualOrderDetail
									.getYmtCouponAmount()))
					.subtract(
							Utils.zeroIfNull(actualOrderDetail
									.getYmtPromotionAmount()))
					.subtract(
							Utils.zeroIfNull(actualOrderDetail
									.getSellerCouponAmount()))
					.subtract(
							Utils.zeroIfNull(actualOrderDetail
									.getPromotionAmount()))
					.subtract(Utils.zeroIfNull(actualOrderDetail
							.getRegionDiscountAmount()));
			
			DataUtil.verifyDecimalEquals(payableAmount,
					actualOrderDetail.getPayableAmount(), "验证数据库PayableAmount");
		}
		
		//订单主状态操作日志表(order_biz_log)
		OrderBizLogPo orderBizLogPo = orderShardingWapper
				.selectOrderBizLogByOrderId(orderId);

		Logger.comment("验证订单业务操作记录表(order_biz_log)");

		String logContent = String.format(
				"运费:%s(old),折扣:%s(old); 运费:%s(new),折扣:%s(new),客服:null", oldFreight,
				order.getOrderPo().getOrderDiscount(),
				changeOrderDiscountReq.getFreight(),
				changeOrderDiscountReq.getDiscount());

		Logger.verifyEquals(logContent, orderBizLogPo.getContent(),
				"验证数据库Content");

		Logger.verifyEquals(orderId, orderBizLogPo.getOrderId(), "验证数据库OrderId");

		Logger.verifyEquals(String.valueOf(orderId), orderBizLogPo.getBizNo(),
				"验证数据库BizNo");
		Logger.verifyEquals(
				BizOperateLogEnum.CHANGE_DISCOUNT_FREIGHT_INFO.toString(),
				orderBizLogPo.getBizType(), "验证数据库BizType");
		Logger.verifyEquals(changeOrderDiscountReq.getSellerId(),
				orderBizLogPo.getOperator(), "验证数据库Operator");
	}
	
	/**
	 * 校验订单组合子商品表（order_detail_sub）
	 * @param expectedOrderDetails
	 * @param actualOrderDetails
	 */
	private void verifyOrderDetailSubDb(OrderDetailPo actualOrderDetail, String currency) {

		long orderDetailId = actualOrderDetail.getOrderDetailId();
		long orderId = actualOrderDetail.getOrderId();

		List<OrderDetailSubPo> subPoList = orderShardingWapper
				.selectOrderDetailSubByDetailId(orderDetailId);

		String catalogId = actualOrderDetail.getCatalogId();

		Logger.comment(String.format(
				"校验订单组合子商品表（order_detail_sub） orderId:%s,catalogId:%s",
				actualOrderDetail.getOrderId(), catalogId));

		BigDecimal[] weight = new BigDecimal[subPoList.size()];

		for (int j = 0; j < subPoList.size(); j++) {

			OrderDetailSubPo orderInfoSubPo = subPoList.get(j);

			weight[j] = orderInfoSubPo.getOriginalPrice().multiply(
					new BigDecimal(orderInfoSubPo.getProductCount()));
		}

		BigDecimal freight[] = Utils.apportionByWeights3(
				actualOrderDetail.getFreight(), weight, currency);
		BigDecimal subDiscount[] = Utils.apportionByWeights3(
				actualOrderDetail.getDiscount(), weight, currency);

		int k = 0;

		for (OrderDetailSubPo actualOrderDetailSub : subPoList) {

			Logger.comment(String.format("套装子商品序号 %s",
					actualOrderDetailSub.getId()));

			Logger.verifyEquals(orderId, actualOrderDetailSub.getOrderId(),
					"验证数据库OrderId");

			Logger.verifyEquals(freight[k], actualOrderDetailSub.getFreight(),
					"验证数据库Freight");

			Logger.verifyEquals(
					true,
					Utils.calcTimeSpanMin(actualOrderDetailSub.getUpdateTime()) < 2,
					"验证数据库UpdateTime跟系统当前时间差为2分钟内");

			DataUtil.verifyDecimalEquals(subDiscount[k],
					actualOrderDetailSub.getDiscount(), "验证数据库Discount");
			k++;
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_001() {
		Logger.start(true, "订单号不存在,修改订单折扣和运费失败");
		try {
			// 参数
			long orderId = 1334;
			long sellerId = 288484;
			BigDecimal discount = new BigDecimal(1);
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(5);
			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(sellerId);
			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();
			
			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyIsContains(ECode.FAILED201_MSG_11,
					changeorderdiscountcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_002() {
		Logger.start(false, "订单号为null");
		try {
			// 参数
			BigDecimal Discount = new BigDecimal(1);
			changeOrderDiscountReq.setDiscount(Discount);

			BigDecimal Freight = new BigDecimal(5);
			changeOrderDiscountReq.setFreight(Freight);
			// changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(111);
			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();
			
			Logger.verifyEquals(ECode.ERROR400,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyIsContains("订单号不能为空",
					changeorderdiscountcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_003() {
		Logger.start(false, "操作用户Id为null");
		try {
			// 参数
			BigDecimal Discount = new BigDecimal(1);
			changeOrderDiscountReq.setDiscount(Discount);

			BigDecimal Freight = new BigDecimal(5);
			changeOrderDiscountReq.setFreight(Freight);
			changeOrderDiscountReq.setOrderId(1111);
			// changeOrderDiscountReq.setSellerId(111);
			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();
			
			Logger.verifyEquals(ECode.ERROR400,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("sellerId:买手ID未提供",
					changeorderdiscountcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_004() {
		Logger.start(false, "运费小于0");
		try {
			// 参数
			BigDecimal Discount = new BigDecimal(1);
			changeOrderDiscountReq.setDiscount(Discount);

			BigDecimal Freight = new BigDecimal(-1);
			changeOrderDiscountReq.setFreight(Freight);
			changeOrderDiscountReq.setOrderId(1111);
			changeOrderDiscountReq.setSellerId(111);

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();
			
			Logger.verifyEquals(ECode.ERROR400,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("freight:" + ECode.FAILED201_MSG_71,
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore // 允许负利润
	public void Tc_SqChangeOrderDiscount_005() {
		Logger.start(true, "代购神器订单,修改的价格等于商家获取的利润，不可修改");
		try {
			// 创建订单

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, autotest_goodsOwnerId);

			OrderItemVo item = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);

			ShenqiProxyChainPo chainInfo = SqTradingProductService
					.getProxyChainInfo(item.getCatalogId(),
							productBean.getSellerId());

			BigDecimal discount = item.getProductPrice()
					.multiply(new BigDecimal(item.getProductNum()))
					.subtract(chainInfo.getFromParentPrice());
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.callPlaceOrderService(placeOrderReq);

			changeOrderDiscountReq.setDiscount(discount.negate());

			BigDecimal Freight = new BigDecimal(5);
			changeOrderDiscountReq.setFreight(Freight);
			changeOrderDiscountReq.setOrderId(placeOrderResp.getOrderList().get(0).getOrderId());
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();
			
			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("订单折扣过低",
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_006() {
		Logger.start(true, "代购神器订单下面有多个商品,上调折扣,校验付款后调整金额的分摊");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, 1);
			
			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 参数
			BigDecimal discount = new BigDecimal(17);
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(38);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			// 付款
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");

			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_007() {
		Logger.start(true, "代购神器订单下面有多个商品,下调价格,校验付款后调整金额的分摊");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, 1);
			
			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 参数
			BigDecimal discount = new BigDecimal(17).negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = BigDecimal.ZERO;

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			// 付款
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");

			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_008() {
		Logger.start(true, "代购神器订单下面有多个商品,币种为日币，下调价格包括小数,调整金额失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain(500058147, 1, false, true);
			String currency = productBean.getCurrency();
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO, 500058147,
							currency);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17.01").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = BigDecimal.ZERO;

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("该币种调价不能含有小数",
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_009() {
		Logger.start(true, "代购神器订单下面有多个商品,币种为日币，下调价格和运费,分摊的价格没有小数");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain(500058147, 1, false, true);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, 500058147);

			//创建一个新的orderItem，并隶属于第一个订单
			OrderItemVo orderItem = SqTradingCallService
					.createOrderItemVo(productBean.getProductId(), productBean
							.getCatalogList().get(1));
			orderItem.setProductPrice(new BigDecimal("2000"));

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItem);

			placeOrderReq.setCurrency(currency);
			placeOrderReq.setDiscount(new BigDecimal("10.00"));

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_010() {
		Logger.start(true, "代购神器订单下面有多个商品,币种为日币，含有税费，下调价格和运费,分摊的价格没有小数");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain(500058147, 1, false, true);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, 500058147);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setBuyDailyLimit(false);

			//创建一个新的orderItem，并隶属于第一个订单
			OrderItemVo orderItemVo2 = SqTradingCallService
					.createOrderItemVo(productBean.getProductId(), productBean
							.getCatalogList().get(1));
			orderItemVo2.setProductPrice(new BigDecimal("2000"));
			
			orderItemVo2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVo2.setBuyDailyLimit(false);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVo2);

			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_011() {
		Logger.start(true, "代购神器订单下面有多个商品,含有税费，下调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setBuyDailyLimit(false);

			//创建一个新的orderItem，并隶属于第一个订单
			OrderItemVo orderItemVo2 = SqTradingCallService
					.createOrderItemVo(productBean.getProductId(), productBean
							.getCatalogList().get(1));
			orderItemVo2.setProductPrice(new BigDecimal("2000"));
			
			orderItemVo2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVo2.setBuyDailyLimit(false);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVo2);

			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
		
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_013() {
		Logger.start(true, "继承代理下单,调价失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 1, true, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeInheritedOrder(productBean,
							(int) mchId, 4321, false);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");
			
			// 参数
			BigDecimal discount = new BigDecimal("1.00");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(38);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(placeOrderResp.getOrderList().get(0).getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("您是分销小店无法改价，请联系渠道商！", changeorderdiscountcall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_014() {
		Logger.start(true, "线下支付订单,调价成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService.placeOrder(
					productBean, BigDecimal.ZERO, autotest_goodsOwnerId,
					productBean.getCurrency(), true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");
			
			// 参数
			BigDecimal discount = new BigDecimal("1.00");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(38);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(placeOrderResp.getOrderList().get(0).getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_015() {
		Logger.start(true, "线下支付订单,买家确认线上支付，调价失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService.placeOrder(
					productBean, BigDecimal.ZERO, autotest_goodsOwnerId,
					productBean.getCurrency(), true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			TradingSyncService.getSyncResult(orderId);
			
			SqTradingCallService.payOrder(userId, placeOrderResp.getTradingId(), "wxsqBuyer", "200");

			Logger.comment("前置数据准备结束");
			
			// 参数
			BigDecimal discount = new BigDecimal("1.00");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(38);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(placeOrderResp.getOrderList().get(0).getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("线下支付，不能调价", changeorderdiscountcall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_016() {
		Logger.start(true, "代购神器订单免运费,含有税费，下调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setBuyDailyLimit(false);
			orderItemVo1.setFullReductionFreeFreight(true);

			placeOrderReq.setCurrency(currency);
			
			placeOrderReq.getOrderGroups().get(0)
					.setServiceRate(new BigDecimal("13.00"));

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_017() {
		Logger.start(true, "代购神器订单0利润，下调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProductPrice(new BigDecimal(productBean
					.getAgentCatalogPriceList().get(0).getDirectPrice()));

			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_018() {
		Logger.start(true, "原订单地址如果开头为香港、澳门等免税地区地址，税费为0，下调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			String address = "海外" + TestDataManager.randomStr(5);
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setBuyDailyLimit(false);

			placeOrderReq.setAddress(address);
			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			
			Thread.sleep(500);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), false, address);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_019() {
		Logger.start(true, "组合商品订单，下调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createComposeProductProxychain((int)autotest_goodsOwnerId, false, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.TEN, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setFullReductionFreeFreight(true);
			orderItemVo1.setSubProduct(true);

			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_020() {
		Logger.start(true, "组合商品订单，上调价格和运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createComposeProductProxychain((int)autotest_goodsOwnerId, false, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(0, BigDecimal.TEN, 20238699,
							productBean, (int) autotest_goodsOwnerId);
			
			OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
					.getOrders().get(0).getOrderItems().get(0);
			
			orderItemVo1.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVo1.setFullReductionFreeFreight(true);
			orderItemVo1.setSubProduct(true);

			placeOrderReq.setCurrency(currency);

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("20");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("27");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					changeorderdiscountcall.getCode(), "验证Code");
			
			// 数据库验证 
			verifyOrderDetailDb(placeOrderResp.getOrderList().get(0), true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_021() {
		Logger.start(true, "使用了积分的订单，调价失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) mchId, 0, false);

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 10L);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			
			// 参数
			BigDecimal discount = new BigDecimal("1.00");
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal(38);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(placeOrderResp.getOrderList().get(0).getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("当前订单使用了积分,不可修改价格", changeorderdiscountcall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_022() {
		Logger.start(true, "带有区域折扣，修改订单折扣和运费失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			String currency = productBean.getCurrency();
			
			PlaceOrderReq placeOrderReq = SqTradingCallService
					.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO,
							20238699L, productBean, autotest_goodsOwnerId);
			
			placeOrderReq.setCurrency(currency);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.setRegionDiscountRatio(new BigDecimal("7.00"));

			TradingServiceResp placeOrderResp = SqTradingCallService.callPlaceOrderService(placeOrderReq);
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("当前订单使用了优惠,不可修改价格",
					changeorderdiscountcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_023() {
		Logger.start(true, "代购神器使用优惠，调价失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.TEN,
							autotest_goodsOwnerId);
			
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("当前订单使用了优惠,不可修改价格",
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_024() {
		Logger.start(true, "修改定金订单的折扣，修改失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);
			
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("预售活动订单不能调价",
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SqChangeOrderDiscount_025() {
		Logger.start(true, "修改二次确认定金订单的折扣，修改失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeSecondConfirmOrder(productBean);
			
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 参数
			BigDecimal discount = new BigDecimal("17").negate();
			changeOrderDiscountReq.setDiscount(discount);

			BigDecimal freight = new BigDecimal("11");

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(productBean.getSellerId());

			// 发送请求
			changeorderdiscountcall.setData(changeOrderDiscountReq);
			changeorderdiscountcall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					changeorderdiscountcall.getCode(), "验证Code");
			Logger.verifyEquals("105", changeorderdiscountcall.getBCode(),
					"验证bcode");
			Logger.verifyEquals("预售活动订单不能调价",
					changeorderdiscountcall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
